How to : refactor code with encapsulate field 如何:用封装字段重构代码
The code that is generated by this refactoring operation is modeled by the encapsulate field code snippets 此重构操作生成的代码将由“封装字段代码段”来建模。
To create the new property , the encapsulate field operation changes the access modifier for the field that you want to encapsulate to 为了创建新属性, “封装字段”操作将为要封装为
For example , if you highlight code that is not a field declaration , you can not select the encapsulate field option 例如,如果突出显示的代码不是字段声明,则无法选择“封装字段”选项。
The encapsulate field operation is only possible when the cursor is positioned on the same line as the field declaration 仅当将光标与字段声明置于同一行时,才可以执行“封装字段”操作。
Available refactoring options include rename , extract method , extract interface , change signature , and encapsulate field 可用的重构选项包括重命名、提取方法、提取接口、更改签名和封装字段。
Other refactoring options include encapsulating fields , promoting local variables to method parameters , and managing method parameters 其他重构选项包括封装字段、将局部变量提升为方法参数以及管理方法参数。
Supports more than 15 individual refactoring features , including operations like reorder parameters , extract method , encapsulate field , and create overload 支持超过15种单独的重构功能,包括重新排列参数、提取方法、封装字段及创建重载等操作。
Encapsulate field refactoring operation enables you to quickly create a property from an existing field , and then seamlessly update your code with references to the new property 利用“封装字段”重构操作,可以从现有字段快速创建属性,然后使用对新属性的引用无缝更新代码。
For declarations that declare multiple fields , encapsulate field uses the comma as a boundary between fields , and initiates refactoring on the field that is nearest the cursor , on the same line as the cursor 对于声明多个字段的声明, “封装字段”使用逗号作为字段之间的边界,并对与光标位于同一行且距离光标最近的某个字段启动重构。